﻿using CPPEI.ETL.DataServiceInterface;
using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using SER = CPPEI.ETL.Domain.Services;

namespace CPPEI.ETL.WebApi
{
    [CPPEI.WebApi.AuthPostAction("ETL", "UpdateCodeConversionRule", "1.0")]
    public class UpdateCodeConversionRuleAction : BaseAction<UpdateCodeConversionRuleParams, UpdateCodeConversionRuleResult>
    {
        protected override ActionResult<UpdateCodeConversionRuleResult> OnExecute(ActionContext context, 
            SysParameters sysParameters,
            UpdateCodeConversionRuleParams opParams)
        {
            SER.CodeConversionRuleService service = new SER.CodeConversionRuleService();
            ServiceResult result = service.Update(context.UserId, opParams.Id, opParams.RawCodes);
            if(result.IsSuccess)
            {
                return new ActionResult<UpdateCodeConversionRuleResult>(new UpdateCodeConversionRuleResult());
            }
            else
            {
                return new ActionResult<UpdateCodeConversionRuleResult>(result.IsSuccess, result.ErrorCode, result.Message, null);
            }
        }
    }

    public class UpdateCodeConversionRuleParams
    {
        [Parameter]
        public Guid Id { get; set; }

        [Parameter]
        public string RawCodes { get; set; }
    }

    public class UpdateCodeConversionRuleResult
    {
    }
}
